/*
 *@本js功能：生成试卷
 *@本js作者：杨锡君
 *@编写时间：2017年11月20日
 */
$(function(){
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    confirm1.init();
    var loading1 = new Loading();
    loading1.init();
    var $testList = $(".testList");
    function testLiModel(opt,url){
        var str = "<li>";
        // if(opt.onlinequestionId != 0 &&  opt.starttime == "0"){
        // 	str+="<img data-onlinequestionid="+ opt.onlinequestionId +" src=\"pc/images/ico_testRabash.png\" class=\"delTest\" >";
        // }
        // if(opt.onlinequestionId != 0 &&  opt.starttime != "0"){
        //    str+="<img data-onlinequestionid="+ opt.onlinequestionId +" src=\"pc/images/ico_haveTest.png\" class=\"haveTest\" ><img data-onlinequestionid="+ opt.onlinequestionId +" src=\"pc/images/ico_testRabash.png\" class=\"delTest\" >";
        // }
        str+="<div style=\"background: "+ opt.courseColer +";\">"
            +"<i class=\"iconfont\">"+ opt.courseTitle +"</i>"
            +"<p title="+ opt.courseName +">"+ opt.courseName +"</p>"
            +"<div class=\"btnBox\">";
        var str1 = "<div class=\"generate\" data-title="+ opt.courseTitle +" data-courseid="+ opt.courseId +" data-coursename="+ opt.courseName +" href=\"javscript:;\">详情</div>";
        // var str1 = "";
        // if(opt.onlinequestionId == 0 && opt.starttime == "0"){
        // 	str1 = "<div class=\"generate\" data-courseid="+ opt.courseId +" data-coursename="+ opt.courseName +" href=\"javscript:;\">生成试卷</div>";
        // }else if(opt.onlinequestionId != 0 &&  opt.starttime == "0"){
        // 	str1 = "<div data-html='"+ opt.textjson +"' data-url="+ url+ opt.fileName +" class=\"previewTest\" href=\"javscript:;\">预览试卷</div><div data-courseid="+ opt.courseId +"  data-onlinequestionid="+ opt.onlinequestionId +"   class=\"startTest\">开始考试</div>";
        // }else{
        //    str1 = "<div data-html='"+ opt.textjson +"'  data-url="+ url+ opt.fileName +"  class=\"previewTest hadTest\" data-courseid="+ opt.courseId +" data-coursename="+ opt.courseName +" href=\"javscript:;\">预览试卷</div>";
        // }
        var str2 = "</div></div>"
            +"</li>";
        return str + str1 + str2;
    }
    var testGenerate = {
        init:function(){
            this.bindEvent();
        },
        bindEvent:function(){
            var self = this;

            self.getDataList();
        },
        getDataList:function(){
            var self = this;
            var jsonStr = JSON.stringify({
                "pageNow":0,
                "pageSize":10
            });
            loading1.show();
            $.ajax({
                type:"post",
                url:"getAllCourseListByTeaIdPost",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    loading1.hide();
                    msg = JSON.parse(msg);
                    $testList.html("");
                    var list = "";
                    if(msg.result == "success"){
                        if(msg.courseList.length!=0){
                            $.map(msg.courseList, function(opt) {
//						$testList.append("<li></li>");
                                list+=testLiModel(opt,msg.url);
                            });
                            $testList.html(list);
                            self.generateEvent();
                        }else{
                            $testList.html("<div style='width: 94%;'><img style='position:relative;margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></div>");
                        }
                    }else{
                        if(msg.failMsg != undefined){
                            if(msg.failMsg == "暂无权限"){
                                parent.location.reload(true);
                            }else{
                                Alert1.content = msg.failMsg;
                                Alert1.init();
                                Alert1.show();
                            }
                        }else{
                            if (msg.errorMsg != "" && msg.errorMsg != undefined) {
                                Alert1.content = msg.errorMsg;
                            } else {
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
                    }

                }
            });
        },
        generateEvent:function(){
            var self = this;
//			生成试题详情
            $(".generate").off("click").click(function(){
                var json = JSON.stringify({
                    "pageName":"testGenerateList",
                    "paramData":{
                        "courseId":Number($(this).attr("data-courseid")),
                        "courseName":$(this).attr("data-coursename"),
                        "courseTitle":$(this).attr("data-title")
                    }
                });
                window.location.href ="skipPage?jsonStr="+json;
            });
        }
    };
    testGenerate.init();
});
